package com.yanxu.proxy.mybatis_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/15-2025
 * @Description: 这里用一句话描述这个类的作用
 */
public class MapperProxyFactory implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String name = method.getName();
        System.out.println("代理增强!!!");
        System.out.println("读取指定位置的配置文件!!!");
        System.out.println("从读取的配置文件文件中获取 " + name + " 对应的sql 语句");

        String sql = "";

        System.out.println("根据sql 语句执行数据库操作!!!");
        return "ok";
    }

    public Object getProxy(Class target) {
        Object proxy = Proxy.newProxyInstance(
                target.getClassLoader(),
                new Class[]{target},
                this
        );
        return proxy;
    }
}